
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>svg 之 pattern · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../svg之clipPath和mask/svg之clipPath和mask.html" />
    
    
    <link rel="prev" href="../svg文本/svg文本.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../svg基础/svg基础.html">
            
                <a href="../svg基础/svg基础.html">
            
                    
                    svg 基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../svg基本图形/svg基本图形.html">
            
                <a href="../svg基本图形/svg基本图形.html">
            
                    
                    svg 基本图形
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../svg之path/svg之path.html">
            
                <a href="../svg之path/svg之path.html">
            
                    
                    svg 之 path
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../svg描边动画/svg描边动画.html">
            
                <a href="../svg描边动画/svg描边动画.html">
            
                    
                    svg 描边动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../svg之fill及fill-rule/svg之fill及fill-rule.html">
            
                <a href="../svg之fill及fill-rule/svg之fill及fill-rule.html">
            
                    
                    svg 之 fill 及 fill-rule
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../svg之viewBox/svg之viewBox.html">
            
                <a href="../svg之viewBox/svg之viewBox.html">
            
                    
                    svg 之 viewBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../svg分组与复用/svg分组与复用.html">
            
                <a href="../svg分组与复用/svg分组与复用.html">
            
                    
                    svg 分组与复用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../svg之marker/svg之marker.html">
            
                <a href="../svg之marker/svg之marker.html">
            
                    
                    svg 之 marker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../svg文本/svg文本.html">
            
                <a href="../svg文本/svg文本.html">
            
                    
                    svg 文本
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.11" data-path="svg之pattern.html">
            
                <a href="svg之pattern.html">
            
                    
                    svg 之 pattern
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../svg之clipPath和mask/svg之clipPath和mask.html">
            
                <a href="../svg之clipPath和mask/svg之clipPath和mask.html">
            
                    
                    svg 之 clipPath 和 mask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../svg之filter/svg之filter.html">
            
                <a href="../svg之filter/svg之filter.html">
            
                    
                    svg 之 filter
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >svg 之 pattern</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="svg-&#x4E4B;-pattern">SVG &#x4E4B; pattern</h1>
<p><code>&lt;pattern&gt;</code> &#x662F; SVG &#x4E2D;&#x7528;&#x4E8E;&#x8BBE;&#x7F6E;&#x586B;&#x5145;&#x56FE;&#x6848;&#x7684;&#x5143;&#x7D20;&#x3002;&#x4E0E;&#x80CC;&#x666F;&#x56FE;&#x7247;&#x586B;&#x5145;&#x6700;&#x5927;&#x533A;&#x522B;&#x5728;&#x4E8E;&#xFF0C;pattern&#x80FD;&#x81EA;&#x5DF1;&#x5B9A;&#x4E49;&#x56FE;&#x6848;&#xFF0C;&#x800C;&#x80CC;&#x666F;&#x586B;&#x5145;&#x9700;&#x8981;&#x63D0;&#x524D;&#x51C6;&#x5907;&#x586B;&#x5145;&#x56FE;&#x7247;&#x3002;</p>
<p><img src="imgs/p0.svg" alt="pattern"></p>
<p>&#x4E0A;&#x56FE;&#x662F; <code>&lt;pattern&gt;</code> &#x5143;&#x7D20;&#x5B9E;&#x73B0;&#x7684;&#x586B;&#x5145;&#x6548;&#x679C;&#x56FE;&#x3002;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x770B;&#x662F;&#x600E;&#x4E48;&#x5B9E;&#x73B0;&#x7684;&#x3002;</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">defs</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x5B9A;&#x4E49;&#x56FE;&#x6848; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern1&quot;</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.1&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.2&quot;</span> &gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#03A9F4&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">rect</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
  <span class="hljs-tag">&lt;/<span class="hljs-name">defs</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- &#x5F15;&#x7528;&#x56FE;&#x6848;&#x586B;&#x5145; --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern1)&quot;</span> /&gt;</span>
</code></pre>
<p><img src="imgs/p1.svg" alt="pattern"></p>
<p>&#x5728;&#x5B9A;&#x4E49;&#x56FE;&#x6848;&#x65F6;&#xFF0C;&#x6307;&#x5B9A; <code>x</code>&#x3001;<code>y</code>&#x3001;<code>width</code>&#x3001;<code>height</code> &#x90FD;&#x662F; <strong>&#x6BD4;&#x4F8B;&#x503C;</strong>&#x3002;&#x56E0;&#x4E3A;&#x8FD9;&#x4E3B;&#x8981;&#x53D7; <code>patternUnits</code> &#x7279;&#x6027;&#x7684;&#x5F71;&#x54CD;&#x3002;&#x90A3;&#x4EC0;&#x4E48;&#x662F; <code>patternUnits</code>?</p>
<h2 id="patternunits">patternUnits</h2>
<p>&#x7528;&#x4E8E;&#x51B3;&#x5B9A; pattern &#x7684; <code>x</code>&#x3001;<code>y</code>&#x3001;<code>width</code>&#x3001;<code>height</code> &#x7684;&#x5982;&#x4F55;&#x8BA1;&#x7B97;&#x3002;&#x6709;&#x5982;&#x4E0B;&#x4E24;&#x79CD;&#x53D6;&#x503C;&#xFF1A;</p>
<ul>
<li><p>objectBoundingBox&#xFF1A;&#x76F8;&#x5BF9;&#x4E8E;&#x5F15;&#x7528;&#x5143;&#x7D20;&#x7684;&#x5BBD;&#x3001;&#x9AD8;&#x8BA1;&#x7B97;&#x3002;&#x9ED8;&#x8BA4;&#x503C;&#x3002;</p>
</li>
<li><p>userSpaceOnUse&#xFF1A;&#x7EDD;&#x5BF9;&#x503C;&#xFF0C;&#x5373;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x8BBE;&#x5B9A;&#x7684;&#x503C;&#x3002;</p>
</li>
</ul>
<p><img src="imgs/p2.svg" alt=""></p>
<p>&#x4ECE;&#x4E0A;&#x56FE;&#x53EF;&#x77E5;&#xFF0C;&#x5F53; <code>patternUnits=&quot;userSpaceOnUse&quot;</code> &#x65F6;&#xFF0C; <code>x</code>&#x3001;<code>y</code>&#x3001;<code>width</code>&#x3001;<code>height</code> &#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x8BBE;&#x5B9A;&#x7684;&#x503C;&#xFF1B;&#x5F53; <code>patternUnits=&quot;objectBoundingBox&quot;</code> &#x65F6;&#xFF0C; <code>x</code>&#x3001;<code>y</code>&#x3001;<code>width</code>&#x3001;<code>height</code> &#x8BBE;&#x5B9A;&#x7684;&#x503C;&#x662F; <strong>&#x6BD4;&#x4F8B;&#x503C;</strong>&#xFF0C;&#x9700;&#x8981;&#x6839;&#x636E;&#x5F15;&#x7528;&#x5143;&#x7D20;&#x7684;&#x5BBD;&#x9AD8;&#x8FDB;&#x884C;&#x8BA1;&#x7B97;&#x3002;&#x5176;&#x4E2D; <code>x</code>&#x3001;<code>width</code> &#x53C2;&#x8003;&#x5F15;&#x7528;&#x5143;&#x7D20;&#x7684;&#x5BBD; <code>w1</code>&#xFF0C;<code>y</code>&#x3001;<code>height</code> &#x53C2;&#x8003;&#x5F15;&#x7528;&#x5143;&#x7D20;&#x7684;&#x9AD8; <code>h1</code>&#x3002;</p>
<p><code>patternUnits</code> &#x7684;&#x8BA1;&#x7B97;&#x539F;&#x7406;&#x4ECB;&#x7ECD;&#x5B8C;&#x4E86;&#x3002;&#x6765;&#x4E2A;&#x5B9E;&#x4F8B;&#x6F14;&#x793A;&#x4E00;&#x4E0B;&#x4E24;&#x79CD;&#x53D6;&#x503C;&#x7684;&#x5B9E;&#x73B0;&#x6548;&#x679C;&#x3002;</p>
<p><img src="imgs/p3.svg" alt=""></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">defs</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- userSpaceOnUse --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern1&quot;</span> <span class="hljs-attr">patternUnits</span>=<span class="hljs-string">&quot;userSpaceOnUse&quot;</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;20&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;20&quot;</span> &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#03A9F4&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">rect</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- objectBoundingBox --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern2&quot;</span> <span class="hljs-attr">patternUnits</span>=<span class="hljs-string">&quot;objectBoundingBox&quot;</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.1&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.2&quot;</span> &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#03A9F4&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">rect</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
<span class="hljs-tag">&lt;/<span class="hljs-name">defs</span>&gt;</span>
<span class="hljs-comment">&lt;!-- &#x5F15;&#x7528; pattern1 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;60&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;40&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern1)&quot;</span>/&gt;</span>
<span class="hljs-comment">&lt;!-- &#x5F15;&#x7528; pattern2 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;320&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;40&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern2)&quot;</span>/&gt;</span>
</code></pre>
<h2 id="patterncontentunits">patternContentUnits</h2>
<p>&#x4E0E; <code>patternUnits</code> &#x7C7B;&#x4F3C;&#xFF0C;&#x53EA;&#x662F;&#x4F5C;&#x7528;&#x5BF9;&#x8C61;&#x4E0D;&#x540C;&#x3002;<code>patternUnits</code> &#x4F5C;&#x7528;&#x4E8E; pattern &#x5143;&#x7D20;&#xFF0C;&#x800C; <code>patternContentUnits</code> &#x4F5C;&#x7528;&#x4E8E; pattern &#x5143;&#x7D20;&#x5185;&#x7684;&#x5185;&#x5BB9;&#x3002;&#x53E6;&#x5916;&#xFF0C;&#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x4E0D;&#x540C;&#x70B9;&#xFF0C;<code>patternUnits</code> &#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x4E3A; <code>objectBoundingBox</code>&#xFF0C;&#x800C; <code>patternContentUnits</code> &#x9ED8;&#x8BA4;&#x503C;&#x4E3A; <code>userSpaceOnUse</code>&#x3002;</p>
<p><img src="imgs/p4.svg" alt=""></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">defs</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- patternUnits=&quot;userSpaceOnUse&quot; patternContentUnits=&quot;userSpaceOnUse&quot; --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern1&quot;</span> <span class="hljs-attr">patternUnits</span>=<span class="hljs-string">&quot;userSpaceOnUse&quot;</span> <span class="hljs-attr">patternContentUnits</span>=<span class="hljs-string">&quot;userSpaceOnUse&quot;</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;20&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;20&quot;</span> &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#03A9F4&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">rect</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
  <span class="hljs-comment">&lt;!-- patternUnits=&quot;userSpaceOnUse&quot; patternContentUnits=&quot;objectBoundingBox&quot; --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern2&quot;</span> <span class="hljs-attr">patternUnits</span>=<span class="hljs-string">&quot;userSpaceOnUse&quot;</span> <span class="hljs-attr">patternContentUnits</span>=<span class="hljs-string">&quot;objectBoundingBox&quot;</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;20&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;20&quot;</span> &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.05&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.1&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#03A9F4&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">rect</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
  <span class="hljs-comment">&lt;!-- patternUnits=&quot;objectBoundingBox&quot; patternContentUnits=&quot;userSpaceOnUse&quot; --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern3&quot;</span> <span class="hljs-attr">patternUnits</span>=<span class="hljs-string">&quot;objectBoundingBox&quot;</span> <span class="hljs-attr">patternContentUnits</span>=<span class="hljs-string">&quot;userSpaceOnUse&quot;</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.1&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.2&quot;</span> &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#03A9F4&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">rect</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
  <span class="hljs-comment">&lt;!-- patternUnits=&quot;objectBoundingBox&quot; patternContentUnits=&quot;objectBoundingBox&quot; --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern4&quot;</span> <span class="hljs-attr">patternUnits</span>=<span class="hljs-string">&quot;objectBoundingBox&quot;</span> <span class="hljs-attr">patternContentUnits</span>=<span class="hljs-string">&quot;objectBoundingBox&quot;</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.1&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.2&quot;</span> &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.05&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.1&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#03A9F4&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">rect</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
<span class="hljs-tag">&lt;/<span class="hljs-name">defs</span>&gt;</span>
<span class="hljs-comment">&lt;!-- pattern1 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;40&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;40&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern1)&quot;</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;red&quot;</span> <span class="hljs-attr">stroke-dasharray</span>=<span class="hljs-string">&quot;4&quot;</span>/&gt;</span>
<span class="hljs-comment">&lt;!-- pattern2 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;320&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;40&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern2)&quot;</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;red&quot;</span> <span class="hljs-attr">stroke-dasharray</span>=<span class="hljs-string">&quot;4&quot;</span>/&gt;</span>
<span class="hljs-comment">&lt;!-- pattern3 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;40&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;220&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern3)&quot;</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;red&quot;</span> <span class="hljs-attr">stroke-dasharray</span>=<span class="hljs-string">&quot;4&quot;</span>/&gt;</span>
<span class="hljs-comment">&lt;!-- pattern4 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;320&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;220&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern4)&quot;</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;red&quot;</span> <span class="hljs-attr">stroke-dasharray</span>=<span class="hljs-string">&quot;4&quot;</span>/&gt;</span>
</code></pre>
<h2 id="patterntransform">patternTransform</h2>
<p>&#x7C7B;&#x4F3C;&#x4E8E; <code>transform</code> &#x6837;&#x5F0F;&#xFF0C;&#x4E13;&#x4E1A;&#x7528;&#x4E8E; <code>pattern</code> &#x5143;&#x7D20;&#x3002;&#x4E0E; <code>patternUnits</code> &#x548C; <code>patternContentUnits</code> &#x7ED3;&#x5408;&#x53EF;&#x4EE5;&#x5236;&#x4F5C;&#x4E00;&#x4E9B;&#x60CA;&#x8273;&#x7684;&#x56FE;&#x6848;&#x6548;&#x679C;&#x3002;</p>
<p><img src="imgs/p5.svg" alt=""></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">defs</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- &#x5B9A;&#x4E49;&#x56FE;&#x6848; --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern1&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.1&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.2&quot;</span> <span class="hljs-attr">patternTransform</span>=<span class="hljs-string">&quot;rotate(-45)&quot;</span> &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#ff9800&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">rect</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
<span class="hljs-tag">&lt;/<span class="hljs-name">defs</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#141414&quot;</span> /&gt;</span>
  <span class="hljs-comment">&lt;!-- &#x5F15;&#x7528;&#x586B;&#x5145;&#x56FE;&#x6848; --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern1)&quot;</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
</code></pre>
<h2 id="xlinkhref-&#x590D;&#x7528;"><code>xlink:href</code> &#x590D;&#x7528;</h2>
<p><code>pattern</code> &#x5143;&#x7D20;&#x8FD8;&#x63D0;&#x4F9B;&#x4E86; <code>xlink:href</code> &#x7279;&#x6027;&#x7528;&#x4E8E; <code>pattern</code> &#x5143;&#x7D20;&#x7684;&#x590D;&#x7528;&#x3002;</p>
<p><img src="imgs/p6.svg" alt=""></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">defs</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;p&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.1&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.2&quot;</span> &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#03A9F4&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">rect</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- &#x590D;&#x7528; pattern1 --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern1&quot;</span> <span class="hljs-attr">xlink:href</span>=<span class="hljs-string">&quot;#p&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.1&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.2&quot;</span> <span class="hljs-attr">patternTransform</span>=<span class="hljs-string">&quot;rotate(-45)&quot;</span> &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
  <span class="hljs-comment">&lt;!-- &#x590D;&#x7528; pattern2 --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern2&quot;</span> <span class="hljs-attr">xlink:href</span>=<span class="hljs-string">&quot;#p&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.2&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.2&quot;</span> &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
<span class="hljs-tag">&lt;/<span class="hljs-name">defs</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;500&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#E1F5FE&quot;</span> /&gt;</span>
  <span class="hljs-comment">&lt;!-- &#x5F15;&#x7528;&#x586B;&#x5145;&#x56FE;&#x6848; pattern1 --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;40&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;40&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern1)&quot;</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;red&quot;</span> <span class="hljs-attr">stroke-dasharray</span>=<span class="hljs-string">&quot;4&quot;</span>/&gt;</span>
  <span class="hljs-comment">&lt;!-- &#x5F15;&#x7528;&#x586B;&#x5145;&#x56FE;&#x6848; pattern2 --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;270&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;40&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern2)&quot;</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;red&quot;</span> <span class="hljs-attr">stroke-dasharray</span>=<span class="hljs-string">&quot;4&quot;</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
</code></pre>
<h2 id="&#x5D4C;&#x5957;-pattern">&#x5D4C;&#x5957; pattern</h2>
<p><code>pattern</code> &#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x652F;&#x6301; <code>pattern</code> &#x5143;&#x7D20;&#x95F4;&#x7684;&#x76F8;&#x4E92;&#x5D4C;&#x5957;&#xFF0C;&#x7528;&#x4E8E;&#x7EC4;&#x5408;&#x56FE;&#x6848;&#x6548;&#x679C;&#x3002;</p>
<p><img src="imgs/p7.svg" alt=""></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">defs</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;p&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.2&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.2&quot;</span> &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;6&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;6&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#03A9F4&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">rect</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
  <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pattern1&quot;</span> <span class="hljs-attr">xlink:href</span>=<span class="hljs-string">&quot;#p&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;0.16&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;0.5&quot;</span> <span class="hljs-attr">patternTransform</span>=<span class="hljs-string">&quot;rotate(-45)&quot;</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x5D4C;&#x5957; #p --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">circle</span> <span class="hljs-attr">cx</span>=<span class="hljs-string">&quot;22&quot;</span> <span class="hljs-attr">cy</span>=<span class="hljs-string">&quot;22&quot;</span> <span class="hljs-attr">r</span>=<span class="hljs-string">&quot;20&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#p)&quot;</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;#03A9F4&quot;</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">&quot;2&quot;</span>/&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span> 
<span class="hljs-tag">&lt;/<span class="hljs-name">defs</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;400&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;#E1F5FE&quot;</span> /&gt;</span>
  <span class="hljs-comment">&lt;!-- &#x5F15;&#x7528;&#x586B;&#x5145;&#x56FE;&#x6848; pattern1 --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">rect</span> <span class="hljs-attr">x</span>=<span class="hljs-string">&quot;50&quot;</span> <span class="hljs-attr">y</span>=<span class="hljs-string">&quot;50&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;300&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;100&quot;</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;url(#pattern1)&quot;</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;red&quot;</span> <span class="hljs-attr">stroke-dasharray</span>=<span class="hljs-string">&quot;4&quot;</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
</code></pre>
<h2 id="viewbox-&#x4E0E;-preserveaspectratio">viewBox &#x4E0E; preserveAspectRatio</h2>
<p><code>pattern</code> &#x5143;&#x7D20;&#x4E5F;&#x6709;&#x81EA;&#x5DF1;&#x7684; viewBox &#x4E0E; preserveAspectRatio &#x7279;&#x6027;&#x3002;&#x5173;&#x4E8E; viewBox &#x4E0E; preserveAspectRatio &#x5DF2;&#x505A;&#x8FC7;&#x76F8;&#x5173;&#x4ECB;&#x7ECD;&#xFF0C;&#x53EF;&#x4EE5;&#x53C2;&#x8003;&#x4E4B;&#x524D;&#x6587;&#x7AE0;&#xFF1A;<a href="../svg&#x4E4B;viewBox/svg&#x4E4B;viewBox.html">svg&#x4E4B;viewBox</a>&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../svg文本/svg文本.html" class="navigation navigation-prev " aria-label="Previous page: svg 文本">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../svg之clipPath和mask/svg之clipPath和mask.html" class="navigation navigation-next " aria-label="Next page: svg 之 clipPath 和 mask">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"svg 之 pattern","level":"1.11","depth":1,"next":{"title":"svg 之 clipPath 和 mask","level":"1.12","depth":1,"path":"svg之clipPath和mask/svg之clipPath和mask.md","ref":"./svg之clipPath和mask/svg之clipPath和mask.md","articles":[]},"previous":{"title":"svg 文本","level":"1.10","depth":1,"path":"svg文本/svg文本.md","ref":"./svg文本/svg文本.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"svg之pattern/svg之pattern.md","mtime":"2019-10-10T08:00:43.751Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-10-21T06:03:10.264Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

